import urllib
import json
from Tweet import *
from HTTP import *

class ProxyDeTwitterReal:
		
	def obtenerTweetsCon(self, terminos):

		terminos_string = " ".join(map(lambda x: '"'+x+'"', terminos))
		query = {
			'q': terminos_string,
			'rpp': 50
		}
		query_string = urllib.urlencode(query)

		http = HTTP()
		req = http.Request('http://search.twitter.com/search.json?'+query_string)
		response = http.urlopen(req)
		contenido = response.read()
		data = json.loads(contenido)

		tweets = set()
		for result in data['results']:
			tweets.add( Tweet(result['text']) )
			
		return tweets
